package com.currency.mall.ui.my.recharge;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.content.ContextCompat;
import android.support.v4.view.ViewPager;

import com.currency.mall.R;
import com.currency.mall.event.OrderEvent;
import com.mifengs.commonbase.base.BaseActivity;
import com.mifengs.commonbase.util.StatusBarCompat;
import com.mifengs.commonbase.util.StatusBarUtils;
import com.ogaclejapan.smarttablayout.SmartTabLayout;
import com.ogaclejapan.smarttablayout.utils.v4.FragmentPagerItem;
import com.ogaclejapan.smarttablayout.utils.v4.FragmentPagerItemAdapter;
import com.ogaclejapan.smarttablayout.utils.v4.FragmentPagerItems;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by Administrator on 2018/12/24.
 */

public class RechargeRecordActivity extends BaseActivity {
    @BindView(R.id.stlayout_recharge)
    SmartTabLayout stlayoutRecharge;
    @BindView(R.id.vp_recharge)
    ViewPager vpRecharge;
    private String[] str = new String[]{"未完成", "已完成", "已取消"};
    private int type= 0;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_recharge_list);
        ButterKnife.bind(this);
        StatusBarCompat.setStatusBarColor(this, ContextCompat.getColor(getContext(), R.color.title_color));
        StatusBarUtils.StatusBarLightMode(this);
        EventBus.getDefault().register(this);
        init();
    }

    private void init() {
        FragmentPagerItems pages = new FragmentPagerItems(getContext());
        for (String titleResId : str) {
            pages.add(FragmentPagerItem.of(titleResId, RechargeRecordFragment.class));
        }
        FragmentPagerItemAdapter adapter = new FragmentPagerItemAdapter(getSupportFragmentManager(), pages);
        vpRecharge.setAdapter(adapter);
        vpRecharge.setCurrentItem(type);
        vpRecharge.setOffscreenPageLimit(3);
        stlayoutRecharge.setViewPager(vpRecharge);
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onMessageEvent(OrderEvent event) {
        switch (event.action) {
            case OrderEvent.ORDER_RECHARGE_STATU:
                if(event.type ==0){
                    type = 0;
                }else if(event.type ==2){
                    type =2;
                }
                init();
                break;
        }
    }

    @OnClick(R.id.tv_title)
    public void onViewClicked() {
        finish();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        EventBus.getDefault().unregister(this);
    }
}
